#pragma once
#include "CSingleton.h"
#include <string>
#include <d3d9.h>
#include <d3dx9.h>
#include "ErrorTrace.h"
#include "Global.h"
#include <dinput.h>

#define KEYBOARD_BUFFER_SIZE	1024

namespace Framework
{
	class CDXManager:public CSingleton<CDXManager>
	{
		friend class CSingleton<CDXManager>;
	public:
		CDXManager();
		~CDXManager(void);
		LPDIRECT3DSURFACE9 LoadSurface(char *);
		bool InitDirectX(HWND hWnd);

		void BeginRender();
		void RenderSurface();
		void EndRender();

		LPDIRECT3DDEVICE9 GetDevice(){return m_pD3DDevice;}
		LPD3DXSPRITE GetDXSprite(){return m_pDXSprite;}

		bool InitKeyboardDevice(HINSTANCE hInst);
		void ProcessKeyBoard();
		int IsKeyDown(int KeyCode);

		virtual void OnKeyDown(int KeyCode){}
		virtual void OnKeyUp(int KeyCode){}
		virtual void ProcessInput(LPDIRECT3DDEVICE9 d3ddv, int Delta){}

	private:	
		bool m_isFull;			
		LPDIRECT3D9 m_pD3D;				//Pointer to interface DirectX graphic
		LPDIRECT3DDEVICE9 m_pD3DDevice;	//Pointer to interface DirectX graphic device
		D3DPRESENT_PARAMETERS m_pD3DPP;	//Parameter to init device graphic
		bool m_isFullScreen;				//Check and change mode of screen (window or fullscreen)
		LPDIRECT3DSURFACE9 m_pSurface ;
		LPDIRECTINPUT8 m_pD3DInput;
		LPDIRECTINPUTDEVICE8 m_pKeyboardDevice;
		LPD3DXSPRITE m_pDXSprite;
		HINSTANCE m_hInstance;

		BYTE  KeyStates[256];	
		DIDEVICEOBJECTDATA KeyEvents[ KEYBOARD_BUFFER_SIZE ];
	};


}
